package tt.dz.egobus.servicemanager.business.convert;

import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;
import tt.dz.egobus.servicemanager.bean.RedisTopicMessage;

/**
 * @author Anson
 * @date 17-8-25
 * @name RedisTopicMessage 转换成redis的key
 * @since 1.0.6
 */
public class RedisTopicMessageKeyConverter implements Converter<RedisTopicMessage, String> {


    @Override
    public String convert(RedisTopicMessage source) {
        if (source == null) {
            return "";
        }

        String[] arrays = new String[4];
        arrays[0] = source.getRedisPre();
        arrays[1] = source.getEventName();
        arrays[2] = source.getBusinessKey();
        arrays[3] = source.getCreateTime() + "";

        if (StringUtils.isAnyEmpty(arrays)) {
            return "";
        }
        String redisKey = StringUtils.join(arrays, RedisTopicMessageConverter.SPLIT_KEY);
        return redisKey;
    }
}
